﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Looptribe.Moodlin8.View.FileOpenPickerPage"
    DataContext="{Binding FileOpenPicker, Source={StaticResource Locator}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Looptribe.Moodlin8.View"
    xmlns:common="using:Looptribe.Moodlin8.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:ExtensionType="FileOpenPicker">

    <Page.Resources>
        <CollectionViewSource x:Name="filesViewSource" Source="{Binding Files}"/>

        <Style x:Key="FileLinkTemplate" TargetType="Button">
            <Setter Property="Background" Value="{StaticResource ButtonBackgroundThemeBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource ButtonForegroundThemeBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonBorderThemeBrush}"/>
            <Setter Property="BorderThickness" Value="{StaticResource ButtonBorderThemeThickness}"/>
            <Setter Property="Padding" Value="12,4,12,4"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Margin="2" Width="300" Height="40">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="40" Height="40">
                                <Image Stretch="UniformToFill">
                                    <Image.Source>
                                        <Binding Path="FileType" Converter="{StaticResource fileTypeConverter}" />
                                    </Image.Source>
                                </Image>
                            </Border>
                            <StackPanel Grid.Column="1" Margin="10,0,0,0">
                                <TextBlock Text="{Binding Name}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" TextTrimming="None"/>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Key="UploadsTemplate">
            <Button Style="{StaticResource FileLinkTemplate}"></Button>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the command area
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid of files fills the remainder -->
        <GridView
            x:Name="fileGridView"
            AutomationProperties.AutomationId="FileGridView"
            AutomationProperties.Name="Files"
            Grid.RowSpan="2"
            ItemsSource="{Binding Source={StaticResource filesViewSource}}"
            ItemTemplate="{StaticResource UploadsTemplate}"
            SelectionMode="Multiple"
            SelectionChanged="FileGridView_SelectionChanged"
            Padding="116,76,116,20"/>

        <!-- Command area -->
        <StackPanel x:Name="commandPanel" Orientation="Horizontal" Margin="120,20,120,30">
            <Button
                AutomationProperties.AutomationId="GoUpButton"
                AutomationProperties.Name="Go Up"
                Click="GoUpButton_Click"
                IsEnabled="{Binding CanGoUp}"
                Margin="-3,-3,35,0"
                Style="{StaticResource TextSecondaryButtonStyle}">
                <TextBlock Text="Go Up" Margin="3,-7,3,10" Style="{StaticResource GroupHeaderTextStyle}" />
            </Button>
        </StackPanel>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="fileGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,76,86,56"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="commandPanel" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100,20,90,30"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
